package com.wyy.controller;

import com.wyy.beans.*;
import com.wyy.service.ParkLotService;
import com.wyy.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class ParkLotController {

    @Autowired
    private ParkLotService parkLotService;

    @PostMapping("/park")
    public Result<Ticket> park(@RequestBody DriverAndCar driverAndCar) {
        return parkLotService.park(driverAndCar.getCar(), driverAndCar.getDriver());
    }

    @PostMapping("/huddleParking")
    Result<List<Ticket>> huddleParking(@RequestBody DriverAndCar driverAndCar){
        return parkLotService.huddleParking(driverAndCar.getCars(), driverAndCar.getDrivers());
    }

    @PostMapping("/parkUp")
    public Result<Car> parkUp(@RequestBody DriverAndTicket driverAndTicket) {
        return parkLotService.parkUp(driverAndTicket.getTicket(), driverAndTicket.getDriver());
    }

    @PutMapping("/parkLot")
    public Result<ParkLot> updateParkLotSpace(@RequestBody ParkLot parkLot) {
        return parkLotService.updateParkLotSpace(parkLot);
    }

    @GetMapping("/parkLot/no/{parkLotNo}")
    public Result<ParkLot> getParkLot(@PathVariable String parkLotNo) {
        return parkLotService.getParkLot(parkLotNo);
    }

    @GetMapping("/parkLot/msg/{licensePlateNo}")
    public Result<Ticket> getParkMsg(@PathVariable String licensePlateNo) {
        return parkLotService.getParkMsg(licensePlateNo);
    }

    @GetMapping("/parkLot/distance")
    public Result<Map<Double, ParkLot>> getAroundParkLotDistances(@RequestBody Driver driver) {
        return parkLotService.getAroundParkLotDistance(driver);
    }

}
